import request from '@/utils/request'
import crypto from 'crypto'

export function login({ username, password }) {
  var sha1 = crypto.createHash('sha1')
  sha1.update(password)
  password = sha1.digest('hex')
  const data = {
    username,
    password
  }
  return request({
    url: '/api/v1/welder-uac-second/user-account-comb/login',
    method: 'post',
    data: { obj: data }
  })
}

export function getInfo(userId) {
  return request({
    url: '/api/v1/welder-uac-second/user-information-comb/show-by-userid/' + userId,
    method: 'post',
    data: {
      d: {
        'fields': [
          {
            'name': 'roleList'
          }
        ]
      }
    }
  })
}
export function updatePwd(origPassword, password) {
  var sha = crypto.createHash('sha1')
  sha.update(origPassword)
  origPassword = sha.digest('hex')
  var sha1 = crypto.createHash('sha1')
  sha1.update(password)
  password = sha1.digest('hex')
  return request({
    url: '/api/v1/welder-uac-second/user-account-comb/update-password',
    method: 'post',
    data: { obj: {
      origPassword,
      password
    }}
  })
}

export function getProjectBySpaceId({ spaceId }) {
  return request({
    url: '/api/v1/welder-sbtx-second/project-info-comb/show-space',
    method: 'post',
    data: {
      d: {
        filters: [{ field: 'spaceId', operator: 'EQUALS', value: spaceId }]
      }
    }
  })
}
